home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Maplin Electronics Catalogue 2001 Winter
/
Maplins Catalogue Winter 2001.iso
/
JScript
/
jshop.bak
< prev
next >
Wrap
Text File
|
2000-12-04
|
3KB
|
118 lines
// jshop.js JavaScript Development by Burgeonet.com
// ****Begin code section for catalog display****
// **Establish array variables. These must match the**
// **catalog array construction in each page.**
var catNo = new Array(); // The catalog number
var itemDesc = new Array(); // The item description
var price = new Array(); // The item price
var itemQty = new Array();
// ****Begin shared cookie functions****
// **Global expdate variable for cookies**
// **Cookie is set to expire in 24 hours**
var expdate = new Date();
expdate.setTime (expdate.getTime() + (7 * 24 * 60 * 60 * 1000))
// **Read cookie data.**
function getCookieData(name) {
var label = name + "="
var cStart = document.cookie.indexOf(label)
var labelLen = label.length
var cLen = document.cookie.length
cStart += labelLen
var tempstr = document.cookie.substring(cStart,cLen)
var cEnd = tempstr.indexOf(";")
if (cEnd == -1) {
cEnd = document.cookie.length
}
return unescape(tempstr.substring(0,cEnd))
}
// **Write cookie data**
function setCookieData(name,value,expires) {
counter ++
document.cookie = name + "=" + counter + "@" + value + "; expires=" + expires + "; Path=" + "/"
}
// **Kill cookie function. When the order is submitted**
// **the cookie is killed via an event handler call.**
function killCookie(name) {
if (getCookieData(name)) {
document.cookie = name + "=" + "; expires = Thu, 01-Jan-70 00:00:01 GMT" + "; Path=" + "/"
cLen = orderString.length
countEnd = orderString.indexOf("@")
pointer = countEnd + 1
counter = orderString.substring(0,countEnd)
cookData = orderString.substring(pointer,cLen)
cookData = ""
counter = 0
history.go(0)
}
}
// ****End shared cookie functions****
// ****Begin code section to update the cookie to ****
// ****add items to the shopping cart cookie 'Scart'.****
// **Global variables.**
var counter = 0
var cookData = ""
// **Extract current value of cookie when page loads **
// **and store the values in the global variables.**
if (getCookieData("Scart")) {
orderString = getCookieData("Scart")
cLen = orderString.length
countEnd = orderString.indexOf("@")
pointer = countEnd + 1
counter = orderString.substring(0,countEnd)
cookData = orderString.substring(pointer,cLen)
}
// **Function to add an item to the shopping cart cookie.**
function addItem(num) {
orderString = getCookieData("Scart")
cLen = orderString.length
countEnd = orderString.indexOf("@")
pointer = countEnd + 1
counter = orderString.substring(0,countEnd)
cookData = orderString.substring(pointer,cLen)
a = eval("catNo[num]")
addCart = '' + a + '`' + itemDesc[num] + '~' + price[num] + '½' + itemQty[num] + '^'
cookData += eval("addCart")
if (confirm("Add ( Qty " + itemQty[num] + " " + a + " " + itemDesc[num] + ' ) to shopping basket')) {
setCookieData("Scart", cookData, expdate.toGMTString())
}
}
// ****End code section for updating the cookie.****
// ****Debugging function to display cookie contents.****
function showMe() {
display = getCookieData("Scart");
}